<template>
	<!--二维码分享 2024年11月28日 09:21:01 by gongxiaohui -->
	<view class="my-container">
		<topBack bgColor="transparent" color="#000">
			<view class="tabs">
				<u-tabs :list="[{name:'App二维码'},{name:'小程序二维码'}]" :inactiveStyle="{
						color: '#333',
						fontSize: '28rpx'
					}" :activeStyle="{
            color: '#3AB1A6',
            fontWeight: 'bold',
            fontSize: '28rpx'
					}" lineWidth="32" lineHeight="6" lineColor="#3AB1A6"
					itemStyle="padding-left: 20rpx; padding-right: 50rpx; height: 90rpx;" @tap="tabChange"></u-tabs>
			</view>
		</topBack>

		<view class="center-arae">
			<view class="content bg-fff radius-32 text-center mlr-48">
				<u-avatar class="avatar" :src="headUrl?ossUrl+headUrl:''" size="160" shape="circle"></u-avatar>
				<view class="font-32 font-weight-600">
					{{realName}}
				</view>
				<view class="font-24 mt-28">{{appName}}专属二维码</view>
				<view class="qrcode-box mt-50">
					<image v-if="currTabIndex==0 && qrcodeInfo.appQrcodeUrl" class="qrcode-img" mode="widthFix"
						:src="ossUrl+qrcodeInfo.appQrcodeUrl">
					</image>
					<image v-if="currTabIndex==1 && qrcodeInfo.mpQrcodeUrl" class="qrcode-img" mode="widthFix"
						:src="ossUrl+qrcodeInfo.mpQrcodeUrl">
					</image>
				</view>
				<view class="logo flex flex-center">
					<image class="logo-img" mode="heightFix" :src="logoImg"></image>
				</view>
			</view>
			<view class="share flex flex-a-center flex-j-ar plr-32">
				<view @tap="saveImage" class="haibao flex-column flex-a-center">
					<u-icon :name="qrcodeDown" size="96"></u-icon>
					<view class="mt-16">保存二维码</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import qrcodeDown from '@/static/sales/qrcode-down.png'
	import {
		ossUrl
	} from '../../utils/tools'
	import {
		getQrcodeChannel
	} from '@/src/service/sales.js'
	export default {
		data() {
			return {
				ossUrl,
				doctorId: '',
				realName: '',
				headUrl: '',
				qrcodeDown,
				qrcodeInfo: {},
				appName: '易起养',
				logoImg: '',
				currTabIndex: 0
			}
		},
		onLoad({
			doctorId,
			realName,
			headUrl
		}) {
			this.doctorId = doctorId
			this.realName = realName
			this.headUrl = headUrl
			this.getQrcode()
		},
		methods: {
			tabChange(e) {
				this.currTabIndex = e.index;
			},
			async getQrcode() {
				const {
					data
				} = await getQrcodeChannel(this.doctorId);
				if (data) {
					this.qrcodeInfo = data
				}
			},
			saveImage() {
				uni.showLoading({
					title: 'Loading...'
				})

				const _filePath = [
					this.ossUrl + this.qrcodeInfo.appQrcodeUrl,
					this.ossUrl + this.qrcodeInfo.mpQrcodeUrl
				]

				// 保存到本地
				uni.saveImageToPhotosAlbum({
					filePath: _filePath[this.currTabIndex],
					success: function() {
						uni.hideLoading()
						uni.showToast({
							title: '保存成功',
							icon: 'success'
						})
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.my-container {
		background-image: url(@/static/home/qrcode-bg.png);
		background-repeat: no-repeat;
		background-size: cover;
		height: 100vh;
		overflow: hidden;

		.tabs {
			width: 540rpx;
		}

		.center-arae {
			height: calc(100vh - 153rpx);
			padding-bottom: 100rpx;
			display: flex;
			flex-direction: column;
			justify-content: space-around;
		}

		.content {
			margin-top: 90rpx;
			padding-top: 116rpx;
			padding-bottom: 3vh;
			position: relative;

			.avatar {
				position: absolute;
				top: -85rpx;
				left: 327rpx;
				border: 8rpx solid #fff;
				box-sizing: content-box;
				transform: translateX(-50%);
			}
		}

		.qrcode-box {
			width: 25vh;
			height: 25vh;
			max-width: 380rpx;
			max-height: 380rpx;
			margin-top: 2vh;
			// background-image: url(@/static/home/qrcode-line-bg.svg);
			// background-repeat: no-repeat;
			// background-size: 100%;
			margin: 0 auto;
			position: relative;
			display: flex;
			align-items: center;
			justify-content: center;

			.qrcode-img {
				width: calc(100% - 56rpx);
			}
		}

		.logo {
			margin-top: 3vh;

			.logo-img {
				height: 72rpx;
			}
		}
	}
</style>